@echo off
:: 设置代码页为UTF-8以支持中文输出
chcp 65001 >nul

setlocal

:: 定义源文件和目标路径
set "SOURCE_CONFIG=build-profile.json5"
set "WIN_DEBUG_TARGET=build_opt\win\build-profile-debug.json5"
set "MAC_DEBUG_TARGET=build_opt\mac\build-profile-debug.json5"
set "WIN_RELEASE_TARGET=build_opt\win\build-profile-release.json5"
set "MAC_RELEASE_TARGET=build_opt\mac\build-profile-release.json5"

:: 定义材料文件夹路径
set "WIN_DEBUG_MATERIAL=build_opt\win\debug\material"
set "MAC_DEBUG_MATERIAL=build_opt\mac\debug\material"
set "WIN_RELEASE_MATERIAL=build_opt\win\release\material"
set "MAC_RELEASE_MATERIAL=build_opt\mac\release\material"

:: 提示用户选择输入
echo 请选择操作:
echo 1 - 当前为调试模式 (保存配置并复制材料)
echo 2 - 当前为发布模式 (保存配置并复制材料)
set /p choice="请输入您的选择 (1/2): "

if "%choice%"=="1" goto :DebugMode
if "%choice%"=="2" goto :ReleaseMode
goto :EOF

:DebugMode
echo 正在保存调试模式配置...
call :CopyConfig "%SOURCE_CONFIG%" "%WIN_DEBUG_TARGET%"
if %errorlevel% neq 0 (
    echo 复制调试模式配置失败.
    goto :EOF
)

call :CopyConfig "%SOURCE_CONFIG%" "%MAC_DEBUG_TARGET%"
if %errorlevel% neq 0 (
    echo 复制调试模式配置失败.
    goto :EOF
)

echo 正在复制调试模式材料...
xcopy /E /I /Y "%WIN_DEBUG_MATERIAL%" "%MAC_DEBUG_MATERIAL%" >nul
if %errorlevel% neq 0 (
    echo 复制调试模式材料失败.
) else (
    echo 成功复制调试模式材料.
)

goto :EOF

:ReleaseMode
echo 正在保存发布模式配置...
call :CopyConfig "%SOURCE_CONFIG%" "%WIN_RELEASE_TARGET%"
if %errorlevel% neq 0 (
    echo 复制发布模式配置失败.
    goto :EOF
)

call :CopyConfig "%SOURCE_CONFIG%" "%MAC_RELEASE_TARGET%"
if %errorlevel% neq 0 (
    echo 复制发布模式配置失败.
    goto :EOF
)

echo 正在复制发布模式材料...
xcopy /E /I /Y "%WIN_RELEASE_MATERIAL%" "%MAC_RELEASE_MATERIAL%" >nul
if %errorlevel% neq 0 (
    echo 复制发布模式材料失败.
) else (
    echo 成功复制发布模式材料.
)

goto :EOF

:CopyConfig
copy /y "%~1" "%~2"
if %errorlevel% neq 0 (
    echo 复制配置文件失败: %~1 到 %~2
    exit /b 1
) else (
    echo 成功复制配置文件: %~1 到 %~2
    exit /b 0
)

:EOF
endlocal